`timescale 1ns/100ps

module tb_cm_fft2_8_top;

    // ============================================================
    // 参数定义
    // ============================================================
    parameter C_DATA_WITH_IN  = 16; // 输入数据位宽
    parameter C_DATA_WITH_OUT = 19; // 输出数据位宽（根据FFT点数合理设置）
    parameter C_N_NUM         = 8;  // FFT点数（如2, 4, 8, 16...）

    // ============================================================
    // 端口信号声明
    // ============================================================
    reg                          I_sys_clk      = 'd0; // 工作时钟 100M
    reg                          I_data_start   = 'd0; // 数据开始进入标志，与第一个数据对齐输入
    reg  [C_DATA_WITH_IN-1:0]    I_data_in_real = 'd0; // 数据输入（实部），从start开始连续输入
    reg  [C_DATA_WITH_IN-1:0]    I_data_in_imag = 'd0; // 数据输入（虚部），从start开始连续输入
    wire                         O_data_start          ; // 数据开始输出标志，与第一个数据对齐输出
    wire [C_DATA_WITH_OUT-1:0]   O_data_out_real       ; // 数据输出（实部），位宽按照最大能力输出
    wire [C_DATA_WITH_OUT-1:0]   O_data_out_imag       ; // 数据输出（虚部），位宽按照最大能力输出

    // ============================================================
    // 时钟生成
    // ============================================================
    always #1 I_sys_clk = ~I_sys_clk;

    // ============================================================
    // 测试激励
    // ============================================================
    initial begin
        repeat (100) @(posedge I_sys_clk); // 等待稳定
        @(posedge I_sys_clk);
        I_data_start   <= 1'b1;
        I_data_in_real <= 16'd1024;
        I_data_in_imag <= 16'd0;
        @(posedge I_sys_clk);
        I_data_start   <= 1'b0;
        I_data_in_real <= 16'd0;
        I_data_in_imag <= 16'd0;

        repeat (6) @(posedge I_sys_clk);

        @(posedge I_sys_clk);
        I_data_start   <= 1'b1;
        I_data_in_real <= 16'd0;
        I_data_in_imag <= 16'd1024;
        @(posedge I_sys_clk);
        I_data_start   <= 1'b0;
        I_data_in_real <= 16'd724;
        I_data_in_imag <= 16'd724;
        @(posedge I_sys_clk);
        I_data_start   <= 1'b0;
        I_data_in_real <= 16'd1024;
        I_data_in_imag <= 16'd0;
        @(posedge I_sys_clk);
        I_data_start   <= 1'b0;
        I_data_in_real <= 16'd724;
        I_data_in_imag <= -16'd724;
        @(posedge I_sys_clk);
        I_data_start   <= 1'b0;
        I_data_in_real <= 16'd0;
        I_data_in_imag <= -16'd1024;
        @(posedge I_sys_clk);
        I_data_start   <= 1'b0;
        I_data_in_real <= -16'd724;
        I_data_in_imag <= -16'd724;
        @(posedge I_sys_clk);
        I_data_start   <= 1'b0;
        I_data_in_real <= -16'd1024;
        I_data_in_imag <= 16'd0;
        @(posedge I_sys_clk);
        I_data_start   <= 1'b0;
        I_data_in_real <= -16'd724;
        I_data_in_imag <= 16'd724;

        @(posedge I_sys_clk);
        I_data_start   <= 1'b1;
        I_data_in_real <= 16'd0;
        I_data_in_imag <= 16'd1024;
        @(posedge I_sys_clk);
        I_data_start   <= 1'b0;
        I_data_in_real <= 16'd1024;
        I_data_in_imag <= 16'd0;
        @(posedge I_sys_clk);
        I_data_start   <= 1'b0;
        I_data_in_real <= 16'd0;
        I_data_in_imag <= -16'd1024;
        @(posedge I_sys_clk);
        I_data_start   <= 1'b0;
        I_data_in_real <= -16'd1024;
        I_data_in_imag <= 16'd0;
        @(posedge I_sys_clk);
        I_data_start   <= 1'b0;
        I_data_in_real <= 16'd0;
        I_data_in_imag <= 16'd1024;
        @(posedge I_sys_clk);
        I_data_start   <= 1'b0;
        I_data_in_real <= 16'd1024;
        I_data_in_imag <= 16'd0;
        @(posedge I_sys_clk);
        I_data_start   <= 1'b0;
        I_data_in_real <= 16'd0;
        I_data_in_imag <= -16'd1024;
        @(posedge I_sys_clk);
        I_data_start   <= 1'b0;
        I_data_in_real <= -16'd1024;
        I_data_in_imag <= 16'd0;
    end

    // ============================================================
    // 实例化被测模块
    // ============================================================
    cm_fft2_8_top #(
        .C_DATA_WITH_IN  (C_DATA_WITH_IN ), // 输入数据位宽
        .C_DATA_WITH_OUT (C_DATA_WITH_OUT), // 输出数据位宽
        .C_N_NUM         (C_N_NUM        )  // FFT点数
    ) cm_fft2_8_top_inst (
        .I_sys_clk       (I_sys_clk      ), // 工作时钟 100M
        .I_data_start    (I_data_start   ), // 数据开始进入标志
        .I_data_in_real  (I_data_in_real ), // 数据输入（实部）
        .I_data_in_imag  (I_data_in_imag ), // 数据输入（虚部）
        .O_data_start    (O_data_start   ), // 数据开始输出标志
        .O_data_out_real (O_data_out_real), // 数据输出（实部）
        .O_data_out_imag (O_data_out_imag)  // 数据输出（虚部）
    );

endmodule